import Vue from 'vue'
import App from './App.vue'
// 2.引入
import VueRouter from 'vue-router'
import Find from '../views/find.vue'
import My from '../views/my.vue'
import notfound from '../views/notfound.vue'
import Part from '../views/part.vue'

import recommend from '../Second/recommend.vue'
import ranking from '../Second/ranking.vue'
import Songlist from '../Second/Songlist.vue'
// 3.注册全局组件
Vue.use(VueRouter)
// 4.规则数组
const routes = [{
    path: "/find",
    component: Find,
    children: [{
        path: "recommend",
        component: recommend
      },
      {
        path: "ranking",
        component: ranking
      },
      {
        path: "Songlist",
        component: Songlist
      },
    ]

  },
  {
    path: "/my",
    component: My
  },
  {
    path: "/part",
    component: Part
  },
  {
    path: "/part/:username",
    component: Part
  },
  {
    path: "/",
    redirect: '/my'
  },
  {
    path: "*",
    component: notfound
  }
]
// 5.生成路由对象
const router = new VueRouter({
  routes
})


Vue.config.productionTip = false

const isLogin = true; // 登录状态(未登录)
router.beforeEach((to, from, next) => {
  if (to.path === "/my" && isLogin === false) {
    alert("请登录")
    next(false) // 阻止路由跳转
  } else {
    next() // 正常放行
  }
})

new Vue({
  router,
  render: h => h(App),
}).$mount('#app')